package EA.testproblems;
import EA.*;

/*
  Goldstein-Price function
  
  Created: 29. sept. 1999
  @version 1.0
  @author Rene Thomsen

(1 + ((x + y + 1)**2)*(19-14*x+3*x*x - 14*y + 6*x*y+3*y*y))*(30+((2*x-3*y)**2)*(18-32*x+12*x*x+48*y-36*x*y+27*y*y))

{[0, -1.000000000], [-.6000000000, -.4000000000], [1.200000000, .8000000000]}   {[-1.737372538, 2], [.8000000000, .2000\
000000], [-2, -.3331421464e-2], [2, -2], [-.1570519696, -2]}


*/

public class GoldsteinPrice extends NumericalProblem 
{

  // Easier way to build max and min
    private double[][] lmax = new double[0][2];
    private double[][] lmin = {{0,-1}};

  public GoldsteinPrice()
    {
      super();

      double[] optimas;

      name = "Goldstein-Price function";
      objectivefunction = new NumericalFitness(){
	      public double Fitness_calcFitness_inner(double[] realpos)
	      {
		  return (1 + Math.pow((realpos[0] + realpos[1] + 1),2)*
			  (19-14*realpos[0]+3*realpos[0]*realpos[0] 
			   - 14*realpos[1] + 
			   6*realpos[0]*realpos[1]+3*realpos[1]*realpos[1]))*
		      (30+Math.pow((2*realpos[0]-3*realpos[1]),2)*
		       (18-32*realpos[0]+12*realpos[0]*realpos[0]+48*realpos[1]-
			36*realpos[0]*realpos[1]+27*realpos[1]*realpos[1]));
	      };
	  };

      dimensions = 2;
      ismaximization = false;
      optimumradius = 0.2;

      intervals = new Interval[2];
      intervals[0] = new Interval(-2, 2);
      intervals[1] = new Interval(-2, 2);
      

      // Set up known maximas
      knownmaxima = new NumericalOptimum[lmax.length];

      for (int i=0;i<lmax.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmax[i][0];
	optimas[1] = lmax[i][1];
	knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
      }

      // Set up known minimas
      knownminima = new NumericalOptimum[lmin.length];

      for (int i=0;i<lmin.length;i++) {
	optimas = new double[dimensions];
	optimas[0] = lmin[i][0];
	optimas[1] = lmin[i][1];
	knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
      }
    }
}
